﻿var LApp = angular.module('LApp', ['ui.router', 'ngAnimate', 'ui.bootstrap', 'angularFileUpload', 'leaflet-directive',  'ngLv']);

LApp.run(function ($rootScope, $templateCache, $state, $lvl) {
    //if (window.localStorage.getItem("PageVersion") != window.PageVersion) {
    //    window.localStorage.setItem("PageVersion", window.PageVersion);
    //    $templateCache.removeAll();
    //}
    $rootScope.$on('$stateChangeSuccess', function () {
    })

    $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
        //开始
        if (!$lvl.storeCompair("AuthorizeVersion", window.AuthorizeVersion)) {
            $lvl.storeItem("AuthorizeVersion", window.AuthorizeVersion);
            $lvl.storeItem("CurrentUser", '');
        }

        var _user = $lvl.storeItem("CurrentUser");

        if (_user) {
            $rootScope.CurrentUser = _user;
        }
        if ($rootScope.CurrentUser) {
            if (toState.name == 'Default' || toState.name == 'Account_LogOn') {
                event.preventDefault();// 取消默认跳转行为
                $state.go("Manager");
            }
        } else {
            if (toState.name != 'Account_LogOn') {
                event.preventDefault();// 取消默认跳转行为
                $state.go("Account_LogOn");
            }
        }
    })

    $rootScope.LogOut = function () {

        $lvl.storeItem("CurrentUser", '');

        $rootScope.CurrentUser = null;

        $state.go("Account_LogOn");

    }

})

LApp.filter('filtermobile', function () {
    return function (input) {
        if (!input) return input;
        if (input.length < 11) return input;
        return input.substring(0, 3) + "****" + input.substring(7, input.length);
    }
})

LApp.filter('filteridentity', function () {
    return function (input) {
        if (!input) return input;
        if (input.length != 18 && input.length != 15) return input; 
        return input.substring(0,5)+"********"+input.substring(13,input.length);
    }
})
